import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import createPersistedState from "vuex-persistedstate"
import * as Cookies from 'js-cookie'
// export const plugins = [createPersistedState()];

const store = () => new Vuex.Store({
    state: {
        address:{
            city_id:'-1',
            initials: "热门",
            name: "北京市",
            province:'110000'
        },
        locationAddress:'定位中',
        venue:[],//场馆列表
        userInfo:{
            user_id:''
        },
        GuserInfo:{
            user_id:''
        },
        audit_status: 1,//店铺状态  2:认证成功/ 1:审核中/ 3:认证失败/ 0:未认证
        store_id: "126",//店铺ID
    },
    mutations: {
        ChangeAddress(state,address) {
            state.address = address
        },
        ChangeLocation(state,location) {
            state.locationAddress = location
        },
        ChangeVenue(state,venue){
            state.venue = venue
            
        },
        ChangeErrMsg(state,errMsg_show) {
            state.errMsg_show = errMsg_show
        },
        ChangeUserInfo(state,userInfo){
            state.userInfo = userInfo
        },
        ChangeAuditStatus(state,audit_status){
            state.audit_status = audit_status
        },
        ChangeStoreId(state,store_id){
            state.store_id = store_id
        },
        ChangeGUserInfo(state,GuserInfo){
            state.GuserInfo = GuserInfo
        }
    },
    actions:{

        nuxtServerInit({commit}, {app}) {
            const data = {}
            data.key= app.$cookies.get('userInfo')||{user_id:''}
            data.GuserInfo= app.$cookies.get('GuserInfo')||{user_id:''}
            // 加载数据到状态树
            commit('ChangeUserInfo', data.key)
            commit('ChangeGUserInfo', data.GuserInfo)
        }
    
    }
    // plugins: [
    //     createPersistedState({
    //         storage: {
    //             getItem: key => Cookies.get(key),
    //             setItem: (key, value) => Cookies.set(key, value, { expires: 3, secure: true }), 
    //             removeItem: key => Cookies.remove(key) 
    //         } 
    //     }) 
    // ]
})

export default store